﻿using CommunityToolkit.Mvvm.Input;
using WPF.Core;
using WPF.Core.Dtos;
using WPF.Core.Services;

namespace WPF.Zero.ViewModels
{
    public partial class RegisterViewModel : DialogViewModel
    {
        public RegisterViewModel(UserService appService)
        {
            Model = new UserModel();
            this.appService = appService;
        }

        private UserModel model;
        private readonly UserService appService;

        public UserModel Model
        {
            get { return model; }
            set { model = value; RaisePropertyChanged(); }
        }

        [RelayCommand]
        private async Task Save()
        {
            if (string.IsNullOrWhiteSpace(Model.UserName)) return;
            await appService.Create(Model);
            OnDialogClosed();
        }

        [RelayCommand]
        private void Cancel()
        {
            OnDialogClosed();
        }
    }
}
